package com.sc.auction.common.exception;

import com.sc.auction.common.util.ExceptionUtils;
import com.sc.auction.common.util.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public R error(Exception e){
        log.error(ExceptionUtils.getMessage(e));
        return R.error().message("全局异常处理");
    }
    @ExceptionHandler(AuctionException.class)
    @ResponseBody
    public R error(AuctionException e){
//        log.error(e.getMessage());
        log.error(ExceptionUtils.getMessage(e));
        return R.error().message(e.getMessage()).code(e.getCode());
    }
}